// package-star/pages/brand-earning/index.js
import { UserInfoUpdateMixins, ManageTargetInfoUpdateMixins } from '../../../behaviors/page';
import { PACKAGE_STAR_PAGE } from '../../../constants/route';
import { navTo, tipToast, showLoading, hideLoading } from '../../../common/env';
import { getSettlementInfo } from '../../../api/brd';
let loaded = false;

Page({
    mixins: [UserInfoUpdateMixins, ManageTargetInfoUpdateMixins],
    data: {
        settlementInfo: {},
    },
    onLoad(options) {
    },
    onShow() {
        this._handleGetDetail();
    },
    async _handleGetDetail() {
        !loaded && showLoading('加载中...');
        const settlementInfo = await getSettlementInfo();
        this.setData({ settlementInfo });
        if (!loaded) hideLoading(); loaded = true;
    },
    handleNavToWithdraw() {
        const { userId } = this.data.userInfo;
        const { ownUserId } = this.data.manageTargetInfo;
        if (userId != ownUserId) {
            tipToast('品牌创建者才能申请提现');
        } else {
            navTo(PACKAGE_STAR_PAGE['brandWithdraw']);
        }
    },
    handleNavToEarningRecord() {
        navTo(PACKAGE_STAR_PAGE['brandEarningRecord']);
    },
    handleNavToWithdrawRecord() {
        const { userId } = this.data.userInfo;
        const { ownUserId } = this.data.manageTargetInfo;
        if (userId != ownUserId) {
            tipToast('品牌创建者才能查看提现记录');
        } else {
            navTo(PACKAGE_STAR_PAGE['brandWithdrawRecord']);
        }
    },
})
